#ifndef VIDEOPULLSTREAM_H
#define VIDEOPULLSTREAM_H

#include "qobject.h"
#include <QThread>
#include<iostream>
#include "qdebug.h"
#include <QImage>

extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}

class VideoPullStream : public QThread
{
    Q_OBJECT
public:
    explicit VideoPullStream(QString _url, QObject* parent = nullptr);
    void stop_pull();

    void run() override {
        _PullFlow();
        cleanup();
    }

signals:
    void frameReady(const QImage& img);

private:
    void cleanup();
    int _PullFlow();

    std::atomic<bool>  stop = true;
    std::atomic<bool>  await = false;

    AVCodecContext* c = nullptr;
    AVFormatContext* pFormatCtx = nullptr;
    uint8_t* buffer = nullptr;

    int videoStream = 0;
    QString url;
};

#endif // VIDEOPULLSTREAM_H
